package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.util.utils.Utils;

public class CalendarViewAdapter extends BaseAdapter {

	private Context mContext;
	private int mCountDay = 42;
	private int mCurrent_mouth_Countday;
	private int mCurrent_Week;
	private int id[] = { R.string.week7, R.string.week1, R.string.week2,
			R.string.week3, R.string.week4, R.string.week5, R.string.week6 };

	public CalendarViewAdapter(Context context, int countday) {
		this.mContext = context;
		this.mCurrent_Week = Utils.getCurrentMonthStart();
		this.mCurrent_mouth_Countday = countday;
	}

	@Override
	public int getCount() {
		return mCountDay;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_calendar, null);
			holder.mTv_calendar_day = (TextView) convertView
					.findViewById(R.id.tv_calendar_day);
			convertView.setTag(holder);
		} else
			holder = (ViewHolder) convertView.getTag();
//		if (position <= 6) {//日期
//			holder.mTv_calendar_day.setTextColor(mContext.getResources().getColor(R.color.mine_lint_text));
//			holder.mTv_calendar_day.setText(mContext.getResources().getString(
//					id[position]));
//		} else {
			if (mCurrent_Week == 7 && (position -6) <= mCurrent_mouth_Countday) {
				holder.mTv_calendar_day.setText(position-6 + "");
			} else if (position -7>= mCurrent_Week
					&& position - mCurrent_Week -6 <= mCurrent_mouth_Countday) {
				holder.mTv_calendar_day.setText(position - mCurrent_Week -6
						+ "");
			}

/*		if (mCurrent_Week == 7 && (position -6) <= mCurrent_mouth_Countday) {
			holder.mTv_calendar_day.setText(position-6 + "");

正确思路		} else if (position >= mCurrent_Week
				&& position - mCurrent_Week -6 <= mCurrent_mouth_Countday) {
			holder.mTv_calendar_day.setText(position - mCurrent_Week +1
					+ "");
			System.out.println("position="+position);
		}*/

//		}
//		if (position % 7 == 6) {
//			holder.mTv_calendar_day.setBackgroundResource(R.mipmap.line_right);
//		}else if (position % 7 == 0) {
//			holder.mTv_calendar_day.setBackgroundResource(R.mipmap.line_left);
//		}
		return convertView;
	}

	class ViewHolder {
		TextView mTv_calendar_day;
	}
}
